﻿using System;
using Autodesk.Revit.DB;
using YJKRevitDimensionText.DimCreator;

namespace YJKRevitDimensionText.VerticalAutoDim.GeoModel
{
	internal class WindowGeo : IPlanarGeo
	{
		public WindowGeo(Element window, Plane pl, Transform transformWcs2Ecs)
		{
			this.Window = (window as FamilyInstance);
			this.plane = pl;
			this.TransformWcs2Ecs = transformWcs2Ecs;
		}

		public Element Element
		{
			get
			{
				return this.Window;
			}
		}

		public int Weight
		{
			get
			{
				return 9;
			}
		}

		public XYZ Max2DPointECS
		{
			get
			{
				return this.Max2DPoint;
			}
		}

		public XYZ Min2DPointECS
		{
			get
			{
				return this.Min2DPoint;
			}
		}

		public XYZ Max3DPointWCS
		{
			get
			{
				return this.Max3DPoint;
			}
		}

		public XYZ Min3DPointWCS
		{
			get
			{
				return this.Min3DPoint;
			}
		}

		public double TopElev
		{
			get
			{
				return this.Max3DPoint.Z;
			}
		}

		public double BottomElev
		{
			get
			{
				return this.Min3DPoint.Z;
			}
		}

		public double Width
		{
			get
			{
				return this.WindowWidth;
			}
		}

		public double Distance2Plane
		{
			get
			{
				return this.dist2Plane;
			}
		}

		public Plane Plane
		{
			get
			{
				return this.plane;
			}
		}

		public bool Init()
		{
			this.WindowWidth = this.Window.Symbol.get_Parameter(BuiltInParameter.CASEWORK_WIDTH).AsDouble();
			double num = this.Window.Symbol.get_Parameter(BuiltInParameter.FAMILY_HEIGHT_PARAM).AsDouble();
			XYZ point = (this.Window.Location as LocationPoint).Point;
			XYZ xyz = DimPublicFunc.CalcProjPointByPlane(point, this.Plane);
			this.dist2Plane = point.DistanceTo(xyz);
			this.Min3DPoint = xyz - this.Plane.XVec * (this.WindowWidth / 2.0);
			this.Max3DPoint = xyz + this.Plane.XVec * (this.WindowWidth / 2.0) + this.Plane.YVec * num;
			this.Min2DPoint = this.TransformWcs2Ecs.OfPoint(this.Min3DPoint);
			this.Max2DPoint = this.TransformWcs2Ecs.OfPoint(this.Max3DPoint);
			return true;
		}

		private Transform TransformWcs2Ecs;

		private readonly Plane plane;

		private readonly FamilyInstance Window;

		private double WindowWidth;

		private double dist2Plane;

		private XYZ Max3DPoint;

		private XYZ Min3DPoint;

		private XYZ Max2DPoint;

		private XYZ Min2DPoint;
	}
}
